
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/18/2013 22:35:51
-- Generated from EDMX file: C:\Users\Sylvain\documents\visual studio 2012\Projects\TaskAttack\TaskAttack.Model\TaskAttack.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
--GO
--USE [taskattack];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_UserProject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectSet] DROP CONSTRAINT [FK_UserProject];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectTaskList]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TaskListSet] DROP CONSTRAINT [FK_ProjectTaskList];
GO
IF OBJECT_ID(N'[dbo].[FK_TaskListTask]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TaskSet] DROP CONSTRAINT [FK_TaskListTask];
GO
IF OBJECT_ID(N'[dbo].[FK_TaskImputation]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ImputationSet] DROP CONSTRAINT [FK_TaskImputation];
GO
IF OBJECT_ID(N'[dbo].[FK_UserImputation]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ImputationSet] DROP CONSTRAINT [FK_UserImputation];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[TaskSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TaskSet];
GO
IF OBJECT_ID(N'[dbo].[UserSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSet];
GO
IF OBJECT_ID(N'[dbo].[ProjectSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectSet];
GO
IF OBJECT_ID(N'[dbo].[TaskListSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TaskListSet];
GO
IF OBJECT_ID(N'[dbo].[ImputationSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ImputationSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'TaskSet'
CREATE TABLE [dbo].[TaskSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [TaskList_Id] int  NOT NULL
);
GO

-- Creating table 'UserSet'
CREATE TABLE [dbo].[UserSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [FirstName] nvarchar(max)  NOT NULL,
    [LastName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ProjectSet'
CREATE TABLE [dbo].[ProjectSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [DaySplit] smallint  NOT NULL,
    [StartDate] datetime  NOT NULL,
    [Owner_Id] int  NOT NULL
);
GO

-- Creating table 'TaskListSet'
CREATE TABLE [dbo].[TaskListSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Project_Id] int  NOT NULL
);
GO

-- Creating table 'ImputationSet'
CREATE TABLE [dbo].[ImputationSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [StartDate] datetime  NOT NULL,
    [ItemCount] nvarchar(max)  NOT NULL,
    [Task_Id] int  NOT NULL,
    [User_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'TaskSet'
ALTER TABLE [dbo].[TaskSet]
ADD CONSTRAINT [PK_TaskSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UserSet'
ALTER TABLE [dbo].[UserSet]
ADD CONSTRAINT [PK_UserSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectSet'
ALTER TABLE [dbo].[ProjectSet]
ADD CONSTRAINT [PK_ProjectSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TaskListSet'
ALTER TABLE [dbo].[TaskListSet]
ADD CONSTRAINT [PK_TaskListSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ImputationSet'
ALTER TABLE [dbo].[ImputationSet]
ADD CONSTRAINT [PK_ImputationSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Owner_Id] in table 'ProjectSet'
ALTER TABLE [dbo].[ProjectSet]
ADD CONSTRAINT [FK_UserProject]
    FOREIGN KEY ([Owner_Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserProject'
CREATE INDEX [IX_FK_UserProject]
ON [dbo].[ProjectSet]
    ([Owner_Id]);
GO

-- Creating foreign key on [Project_Id] in table 'TaskListSet'
ALTER TABLE [dbo].[TaskListSet]
ADD CONSTRAINT [FK_ProjectTaskList]
    FOREIGN KEY ([Project_Id])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectTaskList'
CREATE INDEX [IX_FK_ProjectTaskList]
ON [dbo].[TaskListSet]
    ([Project_Id]);
GO

-- Creating foreign key on [TaskList_Id] in table 'TaskSet'
ALTER TABLE [dbo].[TaskSet]
ADD CONSTRAINT [FK_TaskListTask]
    FOREIGN KEY ([TaskList_Id])
    REFERENCES [dbo].[TaskListSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TaskListTask'
CREATE INDEX [IX_FK_TaskListTask]
ON [dbo].[TaskSet]
    ([TaskList_Id]);
GO

-- Creating foreign key on [Task_Id] in table 'ImputationSet'
ALTER TABLE [dbo].[ImputationSet]
ADD CONSTRAINT [FK_TaskImputation]
    FOREIGN KEY ([Task_Id])
    REFERENCES [dbo].[TaskSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TaskImputation'
CREATE INDEX [IX_FK_TaskImputation]
ON [dbo].[ImputationSet]
    ([Task_Id]);
GO

-- Creating foreign key on [User_Id] in table 'ImputationSet'
ALTER TABLE [dbo].[ImputationSet]
ADD CONSTRAINT [FK_UserImputation]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserImputation'
CREATE INDEX [IX_FK_UserImputation]
ON [dbo].[ImputationSet]
    ([User_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------